package com.bgamq.atcrowd.mvc.controller;

import com.bgamq.atcrowd.entity.Role;
import com.bgamq.atcrowd.service.api.RoleService;
import com.bgamq.atcrowd.util.ResultEntity;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 */
@RestController
public class RoleController {


    private final RoleService roleService;

    @Autowired
    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }



    @RequestMapping(value = "/role/get/page/info.json")
    public ResultEntity<PageInfo<Role>> getPageInfo(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "keyword", defaultValue = "") String keyword

    ) {

        PageInfo<Role> pageInfo = roleService.getPageInfo(pageNum, pageSize, keyword);

        return ResultEntity.successWithData(pageInfo);
    }

    @RequestMapping(value = "/role/save.json", method = RequestMethod.POST)
    public ResultEntity<String> saveRole(Role role) {

        roleService.saveRole(role);

        return ResultEntity.successWithoutData();
    }


    @RequestMapping(value = "/role/update.json",method = RequestMethod.POST)
    public ResultEntity<String > updateRole(Role role){
        roleService.updateRole(role);
        return ResultEntity.successWithoutData();
    }


    @RequestMapping(value = "/role/romove/by/roleid/array.json")
    public ResultEntity<String > romoveRoelById(@RequestBody List<Integer> roleIdList){

        roleService.removeRole(roleIdList);

        return ResultEntity.successWithoutData();
    }
}
